<?php
require_once 'phpmoko/lib/common.php';

class Email
{

	static function getDomain($email)
	{
		return strtolower(substr($email, strpos($email, '@') + 1));
	}

	static function getLocal($email)
	{
		return substr($email, 0, strpos($email, '@'));
	}

	static function isValid($email)
	{
		if (filter_var($email, FILTER_VALIDATE_EMAIL) === false)
			return false;
		return true;
	}

	static function fix($mail)
	{
		$domain = Email::getDomain($mail);
		switch ($domain) {
			case 'hotmai.com':
			case 'homail.com':
			case 'hotmil.com':
			case 'hotmal.com':
			case 'htmail.com':
			case 'hotamil.com':
			case 'hotmail.con':
			case 'otmail.com':
			case 'hotmail.co':
			case 'hotmial.com':
			case 'hotail.com':
			case 'hotmail.cm':
			case 'hotmeil.com':
			case 'hoymail.com':
			case 'gotmail.com':
			case 'htomail.com':
			case 'hotamail.com':
			case 'hotmail.om':
			case 'hptmail.com':
			case 'hotmsil.com':
			case 'hotrmail.com':
			case 'hotnail.com':
			case 'hotmaol.com':
			case 'hotmaail.com':
			case 'hgotmail.com':
			case 'hotmaill.com':
			case 'hormail.com':
			case 'h0tmail.com':
			case 'holmail.com':
			case 'hotmail.ccom':
			case 'hhotmail.com':
			case 'hottmail.com':
			case 'hoptmail.com':
			case 'hotmail.xom':
			case 'hotmail.coml':
			case 'hotmaiil.com':
			case 'hotmail.coom':
			case 'hotmail.cpm':
			case 'haotmail.com':
			case '4hotmail.com':
			case 'yopmail.com':
			case 'hot.mail.com':
			case 'jotmail.com':
			case 'hotmailc.om':
			case 'hotmaqil.com':
			case 'hitmail.com':
			case 'homail.cm':
			case 'hjotmail.com':
			case 'hotmail.cim':
			case 'hotmail.ocm':
			case 'hotmasil.com':
			case 'homtial.com':
			case 'hohmail.com':
			case 'hotmmail.com':
				$domain = 'hotmail.com';
				break;
			case 'hotmai.es':
			case 'hotmil.es':
			case 'hotmal.es':
			case 'homail.es':
			case 'hotamail.es':
			case 'hotmaill.es':
				$domain = 'hotmail.es';
				break;
			case 'gamil.com':
			case 'gmeil.com':
			case 'gmai.com':
			case 'gmial.com':
			case 'gmail.con':
			case 'gamail.com':
			case 'gmail.co':
			case 'gmaill.com':
				$domain = 'gmail.com';
				break;
			case 'yahho.com':
			case 'yahoo.om':
			case 'yahoo.co':
			case 'yahoo.con':
			case 'yaoo.com':
			case 'ahoo.com':
			case 'yaho.com':
			case 'yhoo.com':
				$domain = 'yahoo.com';
				break;
			case 'yaoo.es':
			case 'yaho.es':
				$domain = 'yahoo.es';
				break;
			case 'ahoo.com.ar':
				$domain = 'yahoo.com.ar';
				break;
			case 'yahoo.com.mc':
			case 'yaoo.com.mx':
				$domain = 'yahoo.com.mx';
				break;
			case 'ive.com':
				$domain = 'live.com';
				break;
			case 'ive.com.mx':
				$domain = 'live.com.mx';
				break;
			case 'latimail.com':
				$domain = 'latinmail.com';
				break;
			default:
				return $mail;
		}

		return Email::getLocal($mail) . '@' . $domain;
	}

	/**
	 * Devuelve -2 cuando el correo no es valido
	 *
	 * @param unknown $email
	 * @return string number
	 */
	static function getUrlProvider($email)
	{
		$domain = Email::getDomain($email);

		switch ($domain) {
			case 'adinet.com.uy':
			case 'alice.it':
			case 'facebook.com':
			case 'gmail.com':
			case 'googlemail.com':
			case 'hotmail.be':
			case 'hotmail.ch':
			case 'hotmail.cl':
			case 'hotmail.co.jp':
			case 'hotmail.co.uk':
			case 'hotmail.com':
			case 'hotmail.com.ar':
			case 'hotmail.com.tr':
			case 'hotmail.de':
			case 'hotmail.es':
			case 'hotmail.fr':
			case 'hotmail.it':
			case 'hotmail.se':
			case 'latinmail.com':
			case 'live.cl':
			case 'live.com.ar':
			case 'live.com.mx':
			case 'live.fr':
			case 'live.it':
			case 'mail.ru':
			case 'outlook.com':
			case 'rocketmail.com':
			case 'ymail.com':
				return 'http://' . $domain . '/';

			case 'aol.com':
			case 'live.com':
			case 'yahoo.ca':
			case 'yahoo.cl':
			case 'yahoo.co.jp':
			case 'yahoo.co.uk':
			case 'yahoo.com':
			case 'yahoo.com.ar':
			case 'yahoo.com.au':
			case 'yahoo.com.br':
			case 'yahoo.com.co':
			case 'yahoo.com.mx':
			case 'yahoo.com.ph':
			case 'yahoo.de':
			case 'yahoo.es':
			case 'yahoo.fr':
			case 'yahoo.in':
			case 'yahoo.it':
			case 'yahoo.no':
				return 'http://mail.' . $domain . '/';

			case 'hotmail.co.id':
			case 'mixmail.com':
			case 'ya.com':
				return 'http://www.' . $domain . '/';

			case 'libero.it':
				return 'http://login.' . $domain . '/';

			case 'hispavista.com':
				return 'http://webmail.' . $domain . '/';

			case 'cantv.net':
			case 'terra.com':
			case 'terra.com.co':
			case 'terra.com.mx':
				return 'http://correo.' . $domain . '/';

			case 'att.net':
				return 'https://loginprodx.att.net/';

			case 'terra.com.ve':
				return 'http://correo.terra.com/';

			case 'msn.com':
				return 'http://outlook.com/';

			case 'yahoo.com.ve':
				return 'http://mail.yahoo.com/?.intl=ve';

			case 'eresmas.com':
			case 'wanadoo.es':
				return 'http://correo.orange.es/';

			case 'ono.com':
				return 'http://www.ono.com/correoONO/';

			case 'terra.es':
				return -2;

			default:
				return -1;
		}
	}
}
?>